extends Control
@onready var mouse_effect: Sprite2D = $MouseEffect
var setting_is_opened:bool=false
func _input(event: InputEvent) -> void:
	if event is InputEventMouseButton:
		if event.button_index==MOUSE_BUTTON_LEFT:
			if event.pressed:
				mouse_effect.global_position=Global.player_position+Global.player_screen_pos-event.position
				mouse_effect.play(event.global_position)
				$Audio/MouseAudio.play()
				$Mask/Panel/Skin.play_anim()
			else:
				pass

func _ready() -> void:
	$Mask.modulate.a=0
	$Setting.pivot_offset=$Setting.size/2
	$Setting.modulate=Color(1.0, 1.0, 1.0, 0.5)
	var twn:=create_tween()
	twn.tween_property($Setting,"modulate",Color.WHITE,2)
	twn.tween_property($Setting,"modulate",Color(1.0, 1.0, 1.0, 0.3),2)
	twn.set_loops()
	pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
	if $Mask.mouse_filter==MOUSE_FILTER_STOP:
		$Mask.modulate.a=move_toward($Mask.modulate.a,1.0,delta*2)
	elif $Mask.mouse_filter==MOUSE_FILTER_IGNORE:
		$Mask.modulate.a=move_toward($Mask.modulate.a,0.0,delta*2)
		if $Mask.modulate.a==0.0:$Mask.visible=false
	if mouse_in_setting:
		$Setting.scale=$Setting.scale.move_toward(Vector2.ONE*1.2,delta)
	else:
		$Setting.scale=$Setting.scale.move_toward(Vector2.ONE,delta)



func _on_setting_pressed() -> void:
	if Global.fighting:
		Global.display_str.emit("不要试图逃跑")
		return
	$Mask.visible=true
	$Mask/StopMouse.visible=false
	$Mask.mouse_filter=MOUSE_FILTER_STOP
	$Setting.visible=false
	$Mask/Panel/ExitSetting.visible=true
	get_tree().paused=true
	setting_is_opened=true


var mouse_in_setting:bool=false
func _on_setting_mouse_entered() -> void:
	mouse_in_setting=true


func _on_setting_mouse_exited() -> void:
	mouse_in_setting=false
	pass # Replace with function body.


func _on_exit_setting_pressed() -> void:
	$Mask.mouse_filter=MOUSE_FILTER_IGNORE
	$Mask/StopMouse.visible=true
	$Setting.visible=true
	$Mask/Panel/ExitSetting.visible=false
	get_tree().paused=false
	setting_is_opened=false
